from typing import *


class Solution:

    def topKFrequent(self, nums: List[int], k: int) -> List[int]:
        cnt = Counter(nums)
        scnt = sorted(cnt.items(), key=lambda a: a[1], reverse=True)
        return [v[0] for i, v in enumerate(scnt) if i < k]


s = Solution()
print(s.topKFrequent(nums=[1, 1, 1, 2, 2, 3], k=2))
